<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>todolist</title>
		<style type="text/css">
			.list_con {
				width: 600px;
				margin: 50px auto 0;
			}
			
			.inputtxt {
				width: 550px;
				height: 30px;
				border: 1px solid #ccc;
				padding: 0px;
				text-indent: 10px;
			}
			
			.inputbtn {
				width: 40px;
				height: 32px;
				padding: 0px;
				border: 1px solid #ccc;
			}
			
			.list {
				margin: 0;
				padding: 0;
				list-style: none;
				margin-top: 20px;
			}
			
			.list li {
				height: 40px;
				line-height: 40px;
				border-bottom: 1px solid #ccc;
			}
			
			.list li span {
				float: left;
			}
			
			.list li a {
				float: right;
				text-decoration: none;
				margin: 0 10px;
			}
		</style>

	</head>
	<script type="text/javascript" src="js/jquery-1.12.4.min.js" ></script>

	<body>

		<div class="list_con">
			<h2>To do list</h2>
			<!--文本框-->
			<input type="text" name="" id="txt1" class="inputtxt">
			<!--添加按钮-->
			<input type="button" name="" value="增加" id="btn1" class="inputbtn">

			<ul id="list" class="list">

				<li>
					<span>学习html</span>
					<a href="javascript:;" class="up"> ↑ </a>
					<a href="javascript:;" class="down"> ↓ </a>
					<a href="javascript:;" class="del">删除</a>
				</li>
				
				<li>
					<span>学习css</span>
					<a href="javascript:;" class="up"> ↑ </a>
					<a href="javascript:;" class="down"> ↓ </a>
					<a href="javascript:;" class="del">删除</a>
				</li>
				<li>
					<span>学习javascript</span>
					<a href="javascript:;" class="up"> ↑ </a>
					<a href="javascript:;" class="down"> ↓ </a>
					<a href="javascript:;" class="del">删除</a>
				</li>

			</ul>

		</div>
	</body>
	<script type="text/javascript">
		$("#btn1").click(function(){			
			var value = $("#txt1").val()			
			var oLi = '<li>'+
					'<span>'+value+'</span>'+
					'<a href="javascript:;" class="up"> ↑ </a>'+
					'<a href="javascript:;" class="down"> ↓ </a>'+
					'<a href="javascript:;" class="del">删除</a>'+
					'</li>'
			$("#list").append(oLi)
			$("#txt1").val('')
		})
		//删除 委托
		$("body").delegate(".del","click",function(){
			
			$(this).parent().remove()			
		})		

		//上移
		$(".up").click(function(){			
			if ($(this).parent().index() == 0) {
				alert("到顶了")
			}
			$(this).parent().prev().before($(this).parent())
		})
		//下移
		$(".down").click(function(){
			if ($(this).parent().index() == $("#list li").length-1) {
				alert("已经到底了")
			}
			$(this).parent().next().after($(this).parent())
		})
	</script>

</html>